<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise</title>
</head>

<body>
    <script>
        function getData1 () {
            return new Promise(function (resolve, reject) {
                setTimeout(function () {
                    var a = 111;
                    resolve(a);
                }, 1000)
            })
        }
        function getData2 () {
            return new Promise(function (resolve, reject) {
                setTimeout(function () {
                    var a = 222;
                    resolve(a);
                }, 1000)
            })
        }
        function getData3 () {
            return new Promise(function (resolve, reject) {
                setTimeout(function () {
                    var a = 333;
                    resolve(a);
                }, 1000)
            })
        }

        // bad
        getData1().then(res => {
            console.log(res)
            getData2().then(res => {
                console.log(res)
                getData3().then(res => {
                    console.log(res)
                })
            })
        })

        // good
        getData1()
            .then(res => {
                console.log(res)
                return getData2()
            })
            .then(res => {
                console.log(res)
                return getData3()
            })
            .then(res => {
                console.log(res)
            })

    </script>
</body>

</html>